#ifndef AS_SOCKET_HXX
#define AS_SOCKET_HXX

/* Common Define */
#define INT_TIMEOUT     (60)

struct socketPackageHead
{
    /* data 的长度 */
    int dataLenth;
    /* 收包的长度 */
    int requireLenth;
    /* 此后，跟的是数据 */
    char payload[];
};

void socketTrySetaddress(const string & addr);
string & socketGetaddress(void);

/* Server Only */
#ifdef AS_SOCKET_SERVER

#define INT_SLEEP       (1000)

#ifdef __cplusplus
extern "C" {
#endif
#include <stdlib.h>
/* system sleep*/
#include <unistd.h>
#include "iop_server.h"
void socket_init(void);
void echo_server(void);

#ifdef __cplusplus
}
#endif

class AsSocketServer
{
public:
    AsSocketServer (void);
    ~AsSocketServer(void);
    int exec(void *arg);
    void setStop(void);
    class TestModulesManager* getModluesManager(void)
    {
        return (class TestModulesManager*)m_execArg;
    }
    void addRunningCB(void (*cb)(void*), void* arg);

private:
    /* data */
    iops_t m_base;
    bool   m_stop;
    void*  m_execArg;
    void (*m_runningCB)(void*);
    void *m_runningArg;
};

#endif /* ifndef AS_SOCKET_SERVER */

/* Client Only */
#ifdef AS_SOCKET_CLIENT
#ifdef __cplusplus
extern "C" {
#endif
#include "socket.h"
#ifdef __cplusplus
}
#endif

#include <string>
using std::string;
class AsSocketClient
{
public:
    AsSocketClient (void);
    ~AsSocketClient ();
    int sendRequest2Server(const string & run_mode, const string & cmd, const string & set_value);
    int sendRequest2ServerSingalRequest(struct moduleRequest *request);
    int sendRequest2ServerGetStatusOfAllModulesWithCount(const string & run_mode, const string & cmd);
    //int sendRequest2ServerGetPendingData(struct moduleRequest *request); TODO
    int sendRequest2ServerGetPendingData(const string & run_mode, const string & cmd);

private:
    /* data */
    socket_t m_socket;
};
#endif

#endif /* ifndef AS_SOCKET_HXX */
